package com.song.order.controller;

import com.song.order.entity.Orders;
import com.song.order.service.BookFeignService;
import com.song.order.service.OrderFeignService;
import io.seata.spring.annotation.GlobalTransactional;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author 宋伟宁
 * @Date 2024/1/11
 * @Version 1.0
 **/
@RestController
public class CoustomerController {
    @Resource
    private BookFeignService bookFeignService;
    @Resource
    private OrderFeignService orderFeignService;

    @GlobalTransactional  //TM:开启全局事务
    @GetMapping("/test")
    public String test(long uid,long bid,long sum){
        //先去库存
        Boolean stock = this.bookFeignService.stock(bid, sum);
        //订单
        Orders orders =new Orders();
        orders.setBid(bid);
        orders.setUid(uid);
        orders.setTotal(sum);

        boolean pay = this.orderFeignService.pay(orders);

        return pay&& stock ?"成功":"失败";
    }

}
